﻿using UnityEngine;
using System.Collections;
using UnityEngine.Networking;

public class PlayerHealth : NetworkBehaviour {
	Attribute attribute;
	// Use this for initialization
	void Awake () {
		attribute = GetComponent<Attribute> ();
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	void OnHealthChanged(){
		if (attribute.health <= 0f) {
			if (!isServer) {
				return;
			}
			RpcDied ();
			attribute.health = attribute.maxHealth;
		}
	}
	[ClientRpc]
	void RpcDied(){
		if (isLocalPlayer) {
			gameObject.transform.position = Vector3.zero;
		}
	}
}
